package com.tuling.JUC;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

/**
 * @Type SemophoreUtil.java
 * @Desc
 * @Author wzw
 * @Date 2024/9/10 14:35
 */
public class SemophoreUtil {
    public static void main(String[] args) {
        Semaphore semaphore = new Semaphore(3);
        for (int i = 0; i <6 ; i++) {
            int temp = i;
            int[] aa = {1,2,3};
            List<int[]> list = Arrays.asList(aa);
            new Thread(()->{
                try {
                    semaphore.acquire();
                    System.out.println(temp +"号车抢到车位");
                    TimeUnit.SECONDS.sleep(13);
                    System.out.println(temp+"号车离开");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }finally {

                    semaphore.release();
                }
            },"pool-"+i).start();
        }
    }
}
